<?php 
$req_path="./";
include_once($req_path."include/ini.php");
require_once($req_path."include/db.php");

class M_new extends DB{
	private $dbConn;
	private $rowCount="0";
	private $ID="0";
	private $sqlSelect ="SELECT * FROM tb_news WHERE delete_flage=0 ";
	private $totalpage="0";
	
	function M_new(){
		parent::__construct();
	}
 
	function getListPage(){
		global $list_page;
		return $list_page;
	}
    
	function getNew(){
		global $list_news;
		$sqlscript= $this->sqlSelect;
		
	 	//Order 
		$sqlscript.= " order by created_date DESC " ;

		//Page limit
		$sqlscript.= " limit 0, ".$list_news;
		//paging
		$result = $this->ExecuteData($sqlscript);		
 
		return $result;
	}
	
	function getNewDetail($id=0){
		$sqlscript= " SELECT id, title, description , DATE_FORMAT(created_date , '%d/%m/%Y') CreatedDate ";
		$sqlscript.= " FROM tb_news WHERE delete_flage = 0 and id=".$id ;
		$sqlscript.= " ORDER BY created_date DESC ";
        //print_r( $sqlscript );
		$result = $this->ExecuteData($sqlscript);
		return $result->FetchRow();
	}

	function getRowCount(){
		return $this->rowCount;
	}
	 
	function InsertData($val){
		if (isset($val)){
			$sqlInsert=$this->InsertSqlScript($this->sqlSelect, $val);
			$this->ExecuteData($sqlInsert);
			$this->ID = $this->getLastID();
			return $this->ID;
		}
	}
	function updateData($sql, $val){
		if(isset($val)){
			$sqlUpdate=$this->UpdateSqlScript($sql,$val);
			return $this->ExecuteData($sqlUpdate);
		}
	}
	function delData($id){
		if(isset($id)){
			$sqlDelete = "update tb_position set IsDeleted=1 where ID='".$id."'";
			$this->ExecuteData($sqlDelete);
			return "c";
		}
	}
	function getTotalPage(){
		return $this->totalpage;
	}
}
?>